package com.example.blog.controller.homework;

import com.example.blog.pojo.HomeWork;
import com.example.blog.pojo.Result;
import com.example.blog.service.HomeWorkService;
import com.example.blog.util.TokenUtil.GetCookie;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/homeworks")
public class HomeWorkController {
    @Resource
    private HomeWorkService homeWorkService;

    //提交任务
    @PostMapping("/addHomeWork")
    public Result savaHomeWork(@RequestBody HomeWork homeWork, @RequestParam String subject, HttpServletRequest request) {
        String cookieValue = request.getHeader("Cookie");
        String token = GetCookie.getCookieValue(cookieValue);
        return homeWorkService.savaHomeWork(homeWork, subject, token);
    }

    //查看已提交的任务
    @GetMapping("/getAllHomeWork")
    public Result getSubject(@RequestParam String Subject, HttpServletRequest request) {
        String cookieValue = request.getHeader("Cookie");
        String token = GetCookie.getCookieValue(cookieValue);
        return homeWorkService.getSubject(Subject, token);
    }

    //根据任务id查询详情
    @GetMapping("/getHomeWorkById/{id}")
    public Result getById(@PathVariable int id) {
        return homeWorkService.getHomeWorkById(id);
    }
}
